var util = require('../../utils/util.js');
var api = require('../../config/api.js');
const pay = require('../../services/pay.js');

var app = getApp();
Page({
  data: {
    status: 0,
    orderId: 0
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    this.setData({
      orderId: options.orderId,
      status: options.status
    })
    this.updateSuccess()
  },
  //查看支付结果
  updateSuccess: function () {
    let that = this
    util.request(api.OrderQuery, { orderId: that.data.orderId}).then(function (res) {
      if (res.errno == 0){
        that.setData({ status: 1 })
      } else {
        that.setData({ status: 0 })
      }
    })
  },
  //重新付款
  payOrder() {
    var that = this;
    pay.payOrder(parseInt(that.data.orderId)).then(res => {
      that.setData({
        status: true
      });
      that.updateSuccess();
    }).catch(res => {
      that.updateSuccess();
      util.showErrorToast(res.errmsg);
    });
  }
})